unit Class_GKJG_FL_IN_GKZF;

interface
uses
  Classes,SysUtils,Uni,UniEngine;

type
  TGKJGFLDATATYPE=(gdtNull,gdtText,gdtDoub,gdtMemo,gdtDate);
  
  TGKJGFL=class(TUniEngine)
  private
    FUNITLINK: string;
    FGKJGIDEX: Integer;
    FGKJGFLID: Integer;
    FGKJGFLBH: Integer;
    FGKJGFLMC: string;
    FGKJGFLLX: Integer;
    FGKJGFLDQ: Integer;
    FGKJGFLKD: Integer;
    FGKJGFLLJ: Integer;
    FGKJGFLGQ: Integer;
    FMAJORKEY: Integer;
    FEMPTYKEY: Integer;
    FCORDIDEX: Integer;
    FCORDATTR: Integer;
    FVIEWCODE: string; 
  private
    //not it database
    FIsCreate: Boolean;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;  
  published
    property UNITLINK: string read FUNITLINK write FUNITLINK;
    property GKJGIDEX: Integer read FGKJGIDEX write FGKJGIDEX;
    property GKJGFLID: Integer read FGKJGFLID write FGKJGFLID;
    property GKJGFLBH: Integer read FGKJGFLBH write FGKJGFLBH;
    property GKJGFLMC: string read FGKJGFLMC write FGKJGFLMC;
    property GKJGFLLX: Integer read FGKJGFLLX write FGKJGFLLX;
    property GKJGFLDQ: Integer read FGKJGFLDQ write FGKJGFLDQ;
    property GKJGFLKD: Integer read FGKJGFLKD write FGKJGFLKD;
    property GKJGFLLJ: Integer read FGKJGFLLJ write FGKJGFLLJ;
    property GKJGFLGQ: Integer read FGKJGFLGQ write FGKJGFLGQ;
    property MAJORKEY: Integer read FMAJORKEY write FMAJORKEY;
    property EMPTYKEY: Integer read FEMPTYKEY write FEMPTYKEY;
    property CORDIDEX: Integer read FCORDIDEX write FCORDIDEX;
    property CORDATTR: Integer read FCORDATTR write FCORDATTR;
    property VIEWCODE: string read FVIEWCODE write FVIEWCODE; 
    property IsCreate:Boolean  read FIsCreate write FIsCreate;
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(AGKJGFL:TGKJGFL):TGKJGFL;overload;        
    class procedure CopyIt(AGKJGFL:TGKJGFL;var Result:TGKJGFL);overload;

    class function  ExpSQL(AUnitLink:string;AGZJGIDEX:Integer):string;
    class function  ExpSQL_IN_ALL(AUnitLink:string;AGZJGIDEX:Integer):string;
  end;

implementation

{ TGKJGFL }
procedure TGKJGFL.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('GKJG_IDEX').Value := GKJGIDEX;
        ParamByName('GKJG_FLID').Value := GKJGFLID;
        ParamByName('GKJG_FLBH').Value := GKJGFLBH;
        ParamByName('GKJG_FLMC').Value := GKJGFLMC;
        ParamByName('GKJG_FLLX').Value := GKJGFLLX;
        ParamByName('GKJG_FLDQ').Value := GKJGFLDQ;
        ParamByName('GKJG_FLKD').Value := GKJGFLKD;
        ParamByName('GKJG_FLLJ').Value := GKJGFLLJ;
        ParamByName('GKJG_FLGQ').Value := GKJGFLGQ;
        ParamByName('MAJOR_KEY').Value := MAJORKEY;
        ParamByName('EMPTY_KEY').Value := EMPTYKEY;
        ParamByName('CORD_IDEX').Value := CORDIDEX;
        ParamByName('CORD_ATTR').Value := CORDATTR;
        ParamByName('VIEW_CODE').Value := VIEWCODE;
      end;
      otEdit:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('GKJG_IDEX').Value := GKJGIDEX;
        ParamByName('GKJG_FLID').Value := GKJGFLID;
        ParamByName('GKJG_FLBH').Value := GKJGFLBH;
        ParamByName('GKJG_FLMC').Value := GKJGFLMC;
        ParamByName('GKJG_FLLX').Value := GKJGFLLX;
        ParamByName('GKJG_FLDQ').Value := GKJGFLDQ;
        ParamByName('GKJG_FLKD').Value := GKJGFLKD;
        ParamByName('GKJG_FLLJ').Value := GKJGFLLJ;
        ParamByName('GKJG_FLGQ').Value := GKJGFLGQ;
        ParamByName('MAJOR_KEY').Value := MAJORKEY;
        ParamByName('EMPTY_KEY').Value := EMPTYKEY;
        ParamByName('CORD_IDEX').Value := CORDIDEX;
        ParamByName('CORD_ATTR').Value := CORDATTR;
        ParamByName('VIEW_CODE').Value := VIEWCODE;
      end;  
      otDelt:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('GKJG_IDEX').Value := GKJGIDEX;
        ParamByName('GKJG_FLID').Value := GKJGFLID;
 
      end;  
    end;
  end;
end;

function TGKJGFL.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('GKX_GKJG_FL',['UNIT_LINK',UNITLINK,'GKJG_IDEX',GKJGIDEX,'GKJG_FLID',GKJGFLID],AUniConnection);
end;

function TGKJGFL.GetNextIdex: Integer;
begin

end;

function TGKJGFL.GetNextIdex(AUniConnection: TUniConnection): Integer;
begin
  Result:=CheckField('GKJG_FLID','GKX_GKJG_FL',['UNIT_LINK',UNITLINK,'GKJG_IDEX',GKJGIDEX],AUniConnection);
end;

function TGKJGFL.GetStrDelete: string;
begin
  Result:='DELETE FROM GKX_GKJG_FL WHERE   UNIT_LINK=:UNIT_LINK AND GKJG_IDEX=:GKJG_IDEX AND GKJG_FLID=:GKJG_FLID';
end;

function TGKJGFL.GetStrInsert: string;
begin
  Result:='INSERT INTO GKX_GKJG_FL'
         +'    ( UNIT_LINK, GKJG_IDEX, GKJG_FLID, GKJG_FLBH, GKJG_FLMC'
         +'    , GKJG_FLLX, GKJG_FLDQ, GKJG_FLKD, GKJG_FLLJ, GKJG_FLGQ'
         +'    , MAJOR_KEY, EMPTY_KEY, CORD_IDEX, CORD_ATTR, VIEW_CODE)'
         +'    VALUES'
         +'    (:UNIT_LINK,:GKJG_IDEX,:GKJG_FLID,:GKJG_FLBH,:GKJG_FLMC'
         +'    ,:GKJG_FLLX,:GKJG_FLDQ,:GKJG_FLKD,:GKJG_FLLJ,:GKJG_FLGQ'
         +'    ,:MAJOR_KEY,:EMPTY_KEY,:CORD_IDEX,:CORD_ATTR,:VIEW_CODE)'; 
end;

function TGKJGFL.GetStrsIndex: string;
begin
  Result:=Format('%S-%D-%D',[UNITLINK,GKJGIDEX,GKJGFLID]);
end;

function TGKJGFL.GetStrUpdate: string;
begin
  Result:='UPDATE  GKX_GKJG_FL SET'
         +'    GKJG_FLBH=:GKJG_FLBH,'
         +'    GKJG_FLMC=:GKJG_FLMC,'
         +'    GKJG_FLLX=:GKJG_FLLX,'
         +'    GKJG_FLDQ=:GKJG_FLDQ,'
         +'    GKJG_FLKD=:GKJG_FLKD,'
         +'    GKJG_FLLJ=:GKJG_FLLJ,'
         +'    GKJG_FLGQ=:GKJG_FLGQ,'
         +'    MAJOR_KEY=:MAJOR_KEY,'
         +'    EMPTY_KEY=:EMPTY_KEY,'
         +'    CORD_IDEX=:CORD_IDEX,'
         +'    CORD_ATTR=:CORD_ATTR,'
         +'    VIEW_CODE=:VIEW_CODE'
         +'    WHERE UNIT_LINK=:UNIT_LINK'
         +'    AND   GKJG_IDEX=:GKJG_IDEX'
         +'    AND   GKJG_FLID=:GKJG_FLID'; 
end;

constructor TGKJGFL.Create;
begin
  FUNITLINK:='-1';
  FGKJGIDEX:=1;
  FGKJGFLID:=-1;
  FGKJGFLKD:=80;
  FCORDATTR:=-1;
  FIsCreate:=True;
end;

destructor TGKJGFL.Destroy;
begin

  inherited;
end;

class function TGKJGFL.ReadDS(AUniQuery: TUniQuery): TUniEngine;
begin
  Result:=TGKJGFL.Create;
  with TGKJGFL(Result) do
  begin
    UNITLINK:=AUniQuery.FieldByName('UNIT_LINK').AsString;
    GKJGIDEX:=AUniQuery.FieldByName('GKJG_IDEX').AsInteger;
    GKJGFLID:=AUniQuery.FieldByName('GKJG_FLID').AsInteger;
    GKJGFLBH:=AUniQuery.FieldByName('GKJG_FLBH').AsInteger;
    GKJGFLMC:=AUniQuery.FieldByName('GKJG_FLMC').AsString;
    GKJGFLLX:=AUniQuery.FieldByName('GKJG_FLLX').AsInteger;
    GKJGFLDQ:=AUniQuery.FieldByName('GKJG_FLDQ').AsInteger;
    GKJGFLKD:=AUniQuery.FieldByName('GKJG_FLKD').AsInteger;
    GKJGFLLJ:=AUniQuery.FieldByName('GKJG_FLLJ').AsInteger;
    GKJGFLGQ:=AUniQuery.FieldByName('GKJG_FLGQ').AsInteger;
    MAJORKEY:=AUniQuery.FieldByName('MAJOR_KEY').AsInteger;
    EMPTYKEY:=AUniQuery.FieldByName('EMPTY_KEY').AsInteger;
    CORDIDEX:=AUniQuery.FieldByName('CORD_IDEX').AsInteger;
    CORDATTR:=AUniQuery.FieldByName('CORD_ATTR').AsInteger;
    VIEWCODE:=AUniQuery.FieldByName('VIEW_CODE').AsString;
    
    IsCreate:=False;
  end;  
end;

class procedure TGKJGFL.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
begin
  if Result=nil then Exit;
  with TGKJGFL(Result) do
  begin
    UNITLINK:=AUniQuery.FieldByName('UNIT_LINK').AsString;
    GKJGIDEX:=AUniQuery.FieldByName('GKJG_IDEX').AsInteger;
    GKJGFLID:=AUniQuery.FieldByName('GKJG_FLID').AsInteger;
    GKJGFLBH:=AUniQuery.FieldByName('GKJG_FLBH').AsInteger;
    GKJGFLMC:=AUniQuery.FieldByName('GKJG_FLMC').AsString;
    GKJGFLLX:=AUniQuery.FieldByName('GKJG_FLLX').AsInteger;
    GKJGFLDQ:=AUniQuery.FieldByName('GKJG_FLDQ').AsInteger;
    GKJGFLKD:=AUniQuery.FieldByName('GKJG_FLKD').AsInteger;
    GKJGFLLJ:=AUniQuery.FieldByName('GKJG_FLLJ').AsInteger;
    GKJGFLGQ:=AUniQuery.FieldByName('GKJG_FLGQ').AsInteger;
    MAJORKEY:=AUniQuery.FieldByName('MAJOR_KEY').AsInteger;
    EMPTYKEY:=AUniQuery.FieldByName('EMPTY_KEY').AsInteger;
    CORDIDEX:=AUniQuery.FieldByName('CORD_IDEX').AsInteger;
    CORDATTR:=AUniQuery.FieldByName('CORD_ATTR').AsInteger;
    VIEWCODE:=AUniQuery.FieldByName('VIEW_CODE').AsString;

    IsCreate:=False;
  end;  
end;

class function  TGKJGFL.CopyIt(AGKJGFL: TGKJGFL): TGKJGFL;
begin
  Result:=TGKJGFL.Create;
  TGKJGFL.CopyIt(AGKJGFL,Result)
end;

class procedure TGKJGFL.CopyIt(AGKJGFL:TGKJGFL;var Result:TGKJGFL);
begin
  if Result=nil then Exit;
  Result.UNITLINK:=AGKJGFL.UNITLINK;
  Result.GKJGIDEX:=AGKJGFL.GKJGIDEX;
  Result.GKJGFLID:=AGKJGFL.GKJGFLID;
  Result.GKJGFLBH:=AGKJGFL.GKJGFLBH;
  Result.GKJGFLMC:=AGKJGFL.GKJGFLMC;
  Result.GKJGFLLX:=AGKJGFL.GKJGFLLX;
  Result.GKJGFLDQ:=AGKJGFL.GKJGFLDQ;
  Result.GKJGFLKD:=AGKJGFL.GKJGFLKD;
  Result.GKJGFLLJ:=AGKJGFL.GKJGFLLJ;
  Result.GKJGFLGQ:=AGKJGFL.GKJGFLGQ;
  Result.MAJORKEY:=AGKJGFL.MAJORKEY;
  Result.EMPTYKEY:=AGKJGFL.EMPTYKEY;
  Result.CORDIDEX:=AGKJGFL.CORDIDEX;
  Result.CORDATTR:=AGKJGFL.CORDATTR;
  Result.VIEWCODE:=AGKJGFL.VIEWCODE;    

  Result.IsCreate:=AGKJGFL.IsCreate;
end;

class function TGKJGFL.ExpSQL(AUnitLink: string;
  AGZJGIDEX: Integer): string;
begin
  Result:='SELECT UNIT_LINK'
         +'    ,GKJG_IDEX'
         +'    ,GKJG_FLID'
         +'    ,GKJG_FLBH'
         +'    ,GKJG_FLMC'
         +'    ,GKJG_FLLX'
         +'    ,GKJG_FLDQ'
         +'    ,GKJG_FLKD'
         +'    ,GKJG_FLLJ'
         +'    ,GKJG_FLGQ'
         +'    ,MAJOR_KEY'
         +'    ,EMPTY_KEY'
         +'    ,CORD_IDEX'
         +'    ,CORD_ATTR'
         +'    ,VIEW_CODE'
         +'    FROM GKX_GKJG_FL'
         +'    WHERE UNIT_LINK=%S AND GKJG_IDEX=%D AND GKJG_FLGQ=0'
         +'    ORDER BY GKJG_FLBH';
  Result:=Format(Result,[QuotedStr(AUnitLink),AGZJGIDEX]);
end;

class function TGKJGFL.ExpSQL_IN_ALL(AUnitLink: string;
  AGZJGIDEX: Integer): string;
begin
  Result:='SELECT UNIT_LINK'
         +'    ,GKJG_IDEX'
         +'    ,GKJG_FLID'
         +'    ,GKJG_FLBH'
         +'    ,GKJG_FLMC'
         +'    ,GKJG_FLLX'
         +'    ,GKJG_FLDQ'
         +'    ,GKJG_FLKD'
         +'    ,GKJG_FLLJ'
         +'    ,GKJG_FLGQ'
         +'    ,MAJOR_KEY'
         +'    ,EMPTY_KEY'
         +'    ,CORD_IDEX'
         +'    ,CORD_ATTR'
         +'    ,VIEW_CODE'
         +'    FROM GKX_GKJG_FL'
         +'    WHERE UNIT_LINK=%S AND GKJG_IDEX=%D'
         +'    ORDER BY UNIT_LINK,GKJG_IDEX,GKJG_FLID';
  Result:=Format(Result,[QuotedStr(AUnitLink),AGZJGIDEX]);
end;

end.

